package com.itheima.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.MedicineDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Medicine;
import com.itheima.service.MedicineService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service(interfaceClass = MedicineService.class)
@Transactional
public class MedicineServiceImpl implements MedicineService {
    @Autowired
    private MedicineDao medicineDao;

    @Override
    public PageResult queryPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        PageHelper.startPage(currentPage, pageSize);
        Page<Medicine> medicines = medicineDao.selectByCondition(queryPageBean.getQueryString());
        return new PageResult(medicines.getTotal(), medicines.getResult());
    }

    @Override
    public void add(Medicine medicine) {
        medicineDao.add(medicine);
    }
}
